import worker, { ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@ohos.worker';
import hilog from '@ohos.hilog';

let workerPort: ThreadWorkerGlobalScope = worker.workerPort;

// Worker线程的onmessage逻辑
workerPort.onmessage = function (e: MessageEvents) {

}

workerPort.onmessageerror = function(e : MessageEvents) {
  hilog.info(0x0000, 'workLog', '%{public}s', 'workerPort on message error');
  workerPort.postMessage("error message");
}

/**
 * Defines the event handler to be called when an exception occurs during worker execution.
 * The event handler is executed in the worker thread.
 *
 * @param e error message
 */
workerPort.onerror = function(e : ErrorEvent) {
  hilog.info(0x0000, 'workLog', '%{public}s %{error}', 'workerPort on error', e.message);
  workerPort.postMessage("error");
}